<?php

namespace app\common\model;

use app\hander\HelpHander;
use think\Db;
use think\Model;
use think\model\concern\SoftDelete;

class User extends Model
{
	const REGISTER_CODE = 1;//注册
	const LOGIN_CODE = 2;//登录
	protected $autoWriteTimestamp = true;
	protected $auto = [ 'activity_time' ];
	protected $insert = [ 'token', 'status' => 1 ];
	protected $update = [];
	protected $type = [
		'id'            => 'integer',
		'status'        => 'integer',
		'activity_time' => 'timestamp:Y-m-d H:i:s',
	];
	
	/**
	 * 最后活动时间 自动完成
	 * @Function setActivityTimeAttr
	 * @return int
	 * @Author   tegic
	 * @Time     2018/6/4 10:39
	 */
	protected function setActivityTimeAttr()
	{
		return time();
	}
	
	/**
	 * 根据搜索条件获取用户列表信息
	 */
	public function getUserByWhere($map, $Nowpage, $limits)
	{
		$data = $this->with('profile')->where($map)->page($Nowpage, $limits)->order('id desc')->select();
		return $data;
	}
	
	/**
	 * 根据搜索条件获取所有的用户数量
	 *
	 * @param $where
	 */
	public function getAllCount($map)
	{
		return $this->where($map)->count();
	}
	
	public function profile()
	{
		return $this->hasOne('Profile');
	}
}
